import { Component, OnInit } from '@angular/core';
import {markdown} from 'markdown';
import {ActivatedRoute, Router} from '@angular/router';
import {DomSanitizer} from '@angular/platform-browser';
import {LifeService} from '../../../shared/service/life.service';
import {HttpParams} from '@angular/common/http';

@Component({
  selector: 'app-diary-detail',
  templateUrl: './diary-detail.component.html',
  styleUrls: ['./diary-detail.component.scss']
})
export class DiaryDetailComponent implements OnInit {
  diary;

  html;
  constructor(
    public router: Router,
    public activeRoute: ActivatedRoute,
    private domSanitizer: DomSanitizer,
    private lifeService: LifeService,
  ) { }

  ngOnInit() {
    this.activeRoute.params.subscribe((res) => {
      const params = new HttpParams().set('id', res.id);
      this.lifeService.getDiaryDetail(params).subscribe((result) => {
        this.diary = result;
        this.html = markdown.toHTML(this.diary.detail);
        this.html = this.domSanitizer.bypassSecurityTrustHtml(this.html);
      });
    });
  }

}
